﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Default/Shared/Site.Master"
    Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="SystemContent" runat="server">
    <%using (Html.BeginForm())
      { %>
    <div class="pitem" style="margin-top: 25px;">
        <em>请输入宝宝的姓：</em>
        <%=Html.TextBox("Surname", "", new { @class = "f-text", id = "surname", maxlength = "20", style = "width: 150px;", onblur = "javascript:checksurname();" })%>
        <span class="errors" id="spansurname" style="display: none;"></span>
    </div>
    <div class="pitem">
        <em>请选择宝宝的性别：</em> <%=Html.RadioButton("Sex",0,true)%>男孩&nbsp;&nbsp;&nbsp;&nbsp;
        <%=Html.RadioButton("Sex",1)%>女孩
        <span class="errors" id="sex" style="display: none;"></span>
    </div>
    <div class="pitem">
        <em>请选择宝宝的生日：</em>
        <%=Html.DropDownList("BirthdayYear",ViewData["BirthdayYear"] as SelectList,DateTime.Now.Year.ToString(), new { id = "birthdayYear", onchange = "javascript:birthday();" })%>
        年
        <%=Html.DropDownList("BirthdayMonth", ViewData["BirthdayMonth"] as SelectList,DateTime.Now.Month.ToString(), new { id = "birthdayMonth", onchange = "javascript:birthday();" })%>
        月
        <%=Html.DropDownList("BirthdayDay", ViewData["BirthdayDay"] as SelectList,DateTime.Now.Day.ToString(), new { id = "birthdayDay", onchange = "javascript:birthday();" })%>
        日 <span class="warn" id="spanBirthday">未出生的可选择预产期</span> <span class="errors"
            id="spanbirthday" style="display: none;"></span>
    </div>
    <div class="pitem">
        <em>请选择宝宝名字的结构：</em>
        <%=Html.DropDownList("NameStruc", ViewData["NameStruc"] as SelectList, new { id = "nameStruc", onchange = "javascript:SetNameStruc();" })%>
        <span class="warn" id="spanNameStrucWarn">例如：刘德华</span> 
        <span class="errors" id="spanNameStrucError" style="display: none;"></span>
    </div>
    <div class="pitem">
        <em>已确定的字：</em>
        <%=Html.DropDownList("KnowWord", ViewData["KnowWord"] as SelectList, new { id = "ddKnowWord",onchange = "javascript:SetKnowWord();" })%>&nbsp;&nbsp;
        <%=Html.TextBox("knowWord", "", new { @class = "f-text", id = "tbKnowWord", maxlength = "20", style = "width: 150px;", onblur = "javascript:checkknowword();" })%>
        <span class="warn" id="spanKnowWordWarn">此栏可不填</span> 
        <span class="errors" id="spanKnowWord" style="display: none;"></span>
    </div>
    <div class="pitemname" style="margin-top: 25px;">
        <em>宝宝名字：</em> 
            <div class="matts_null" id="matts1"><table style="margin:auto;"><tr><td></td></tr></table>
            </div>
            <div class="matts_null" id="matts2"><table style="margin:auto;"><tr><td></td></tr></table>
            </div>
            <div class="matts_null" id="matts3"><table style="margin:auto;"><tr><td></td></tr></table>
            </div>
            <div class="matts_null" id="matts4" style="display: none;"><table style="margin:auto;"><tr><td></td></tr></table>
            </div>
    </div>
    <div class="pitem1">
        <em>&nbsp;</em>
        <input type="submit" name="button1" id="SubmitSend" class="btn_blue6" onclick="return checkdata();"
            value="下一步" />
    </div>
    <%} %>
<script type="text/javascript">

    function setFormUi() {
        var username = jQuery("#surname").val();
        var lu = username.length;
        var nameStrucType = jQuery("#nameStruc").val();
        var knowWord = jQuery("#ddKnowWord").val();
        var KnowWordValue = jQuery("#tbKnowWord").val();
        var kt = false;
        if (nameStrucType == "3") {
            nameStrucType = "1";
            kt = true;
        }
            
        //lu 1:单姓 2：双姓
        //nameStrucType 1：双字 2:单字
        //knowWord 1：第一个字 2：第二个字
        var UiType = lu + nameStrucType + knowWord;
        switch (UiType) {
            case "111":
                {
                    jQuery("#matts1").show();
                    jQuery("#matts2").show();
                    jQuery("#matts3").hide();
                    jQuery("#matts4").hide();
                    jQuery("#matts1").html(username.substring(0, 1));
                    jQuery("#matts2").html("");
                }
                break;
            case "112":
                {
                    jQuery("#matts1").show();
                    jQuery("#matts2").show();
                    jQuery("#matts3").hide();
                    jQuery("#matts4").hide();
                    jQuery("#matts1").html(username.substring(0, 1));
                    jQuery("#matts2").html("");
                }
                break;
            case "121":
                {
                    jQuery("#matts1").show();
                    jQuery("#matts2").show();
                    jQuery("#matts3").show();
                    jQuery("#matts4").hide();
                    jQuery("#matts1").html(username.substring(0, 1));
                    if (KnowWordValue.length > 0) {
                        jQuery("#matts2").html(KnowWordValue);
                    }
                    else {
                        jQuery("#matts2").html("");
                    }
                    jQuery("#matts3").html("");
                }
                break;
            case "122":
                {
                    jQuery("#matts1").show();
                    jQuery("#matts2").show();
                    jQuery("#matts3").show();
                    jQuery("#matts4").hide();
                    jQuery("#matts1").html(username.substring(0, 1));
                    if (KnowWordValue.length > 0) {
                        jQuery("#matts3").html(KnowWordValue);
                    }
                    else {
                        jQuery("#matts3").html("");
                    }
                    jQuery("#matts2").html("");
                }
                break;
            case "211":
                {
                    jQuery("#matts1").show();
                    jQuery("#matts2").show();
                    jQuery("#matts3").show();
                    jQuery("#matts4").hide();
                    jQuery("#matts1").html(username.substring(0, 1));
                    jQuery("#matts2").html(username.substring(1, 2));
                    jQuery("#matts3").html("");
                }
                break;
            case "212":
                {
                    jQuery("#matts1").show();
                    jQuery("#matts2").show();
                    jQuery("#matts3").show();
                    jQuery("#matts4").hide();
                    jQuery("#matts1").html(username.substring(0, 1));
                    jQuery("#matts2").html(username.substring(1, 2));
                    jQuery("#matts3").html("");
                }
                break;
            case "221":
                {
                    jQuery("#matts1").show();
                    jQuery("#matts2").show();
                    jQuery("#matts3").show();
                    jQuery("#matts4").show();
                    jQuery("#matts1").html(username.substring(0, 1));
                    jQuery("#matts2").html(username.substring(1, 2));
                    if (KnowWordValue.length > 0) {
                        jQuery("#matts3").html(KnowWordValue);
                    }
                    else {
                        jQuery("#matts3").html("");
                    }
                    jQuery("#matts4").html("");
                }
                break;
            case "222":
                {
                    jQuery("#matts1").show();
                    jQuery("#matts2").show();
                    jQuery("#matts3").show();
                    jQuery("#matts4").show();
                    jQuery("#matts1").html(username.substring(0, 1));
                    jQuery("#matts2").html(username.substring(1, 2));
                    if (KnowWordValue.length > 0) {
                        jQuery("#matts4").html(KnowWordValue);
                    }
                    else {
                        jQuery("#matts4").html("");
                    }
                    jQuery("#matts3").html("");
                }
                break;
        }
        
    }

    function checksurname() {
        var err = "";
        var username = jQuery("#surname").val();
        var l = username.length;

        if (username == "") {
            err += "填写宝宝的姓\n";
        }
        else {
            if (!/^[\u4E00-\u9FA5]{1,2}$/.test(username)) {
                err += "宝宝的姓由1-2个中文组成。暂不支持三个以上中文的姓以及英文姓。";
            }
        }
        if (err != "") {
            jQuery("#spansurname").show();
            jQuery("#spansurname").html(err);
            return false;
        }
        else {
            jQuery("#spansurname").hide();

            setFormUi();
            //return true;
        }
    }

    function checkknowword() {
        
        var err = "";
        var knowword = jQuery("#tbKnowWord").val();
        var lk = knowword.length;
        
        if (!/^[\u4E00-\u9FA5]{0,1}$/.test(knowword)) {
            err += "只能是一个汉字。";
        }
        if (err != "") {
            jQuery("#spanKnowWord").show();
            jQuery("#spanKnowWord").html(err);
            return false;
        }
        else {
            jQuery("#spanKnowWord").hide();

            setFormUi();
            //return true;
        }
        
    }

    function birthday() {
        var err = "";
        var year = jQuery("#birthdayYear").val();
        var month = jQuery("#birthdayMonth").val();
        var day = jQuery("#birthdayDay").val();
        if (!isRightDay(year, month, day)) {
            err += "请选择正确的日期。";
        }

        if (err != "") {
            jQuery("#spanbirthday").show();
            jQuery("#spanbirthday1").hide();
            jQuery("#spanbirthday").html(err);
            return false;
        }
        else {
            jQuery("#spanbirthday1").show();
            jQuery("#spanbirthday").hide();
            return true;
        }
    }
    function isRightDay(year,month,day)
    {

        switch(month)
        {
            case "2":
                if((year % 4 ==0 && day >29 ) || (year % 4 !=0 && day >28 ))
                {
                    return false;
                }
                break;
            case "4":
            case "6":
            case "9":
            case "11":
                if(day>30)
                {
                    return false;
                }
                break;

        }
        return true;
    }

    function checkdata() {
        if (checksurname() == false) { jQuery("#surname").focus(); return false; }
        if (!birthday()) { jQuery("#birthdayYear").focus(); return false; }
        return true;
    }
    function SetNameStruc() {
        var nameStrucType = jQuery("#nameStruc").val();
        switch (nameStrucType) {
            case "1":
                {
                    jQuery("#spanNameStrucWarn").html("例如：赵薇、司马燕");
                }
                break;
            case "2":
                {
                    jQuery("#spanNameStrucWarn").html("例如：刘德华、欧阳夏丹");
                }
                break;
            case "3":
                {
                    jQuery("#spanNameStrucWarn").html("例如：范冰冰、慕容晓晓");
                }
                break;
        }
        setFormUi();
    }

    function SetKnowWord() {
        setFormUi();
    }
</script>
</asp:Content>
